<?php if(!defined('BASEPATH'))exit('No direct script access allowed');
class sanpham extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->library('addin');
	}
	public function index($sotrang=1)
	{
		if(!is_numeric($sotrang)) $sotrang = 1;
		$this->load->library('pagination');
		$this->load->model('sanpham_model');
		$data2['sanpham'] = $this->sanpham_model->getAllSP($sotrang);
		if(count($data2['sanpham'])<=0) echo redirect(base_url());
		
		$config['base_url'] = base_url('sanpham/index');
		$config['first_link'] = '<<';
		$config['last_link'] = '>>';
		$config['anchor_class'] = 'class="pagin"'; 
		$config['total_rows'] = $this->sanpham_model->countAllSP();
		$config['per_page'] = 1;
		$config['use_page_numbers'] = TRUE;
		$this->pagination->initialize($config);
		$data2['phantrang'] = $this->pagination->create_links();
		
		$data1['thongke'] = $this->addin->thongKe();
		$data1['counter'] = $this->addin->getcounter();
		$data1['online'] = $this->addin->getonline();
		$data1['menu1'] = $this->addin->getMenuMain();
		$data1['menu2'] = $this->addin->getMenu3Cap();
        $data1['noibat'] = $this->sanpham_model->getNoiBat();
		$this->load->view('required/header-trangcon',$data1);
		$this->load->view('sanpham/index',$data2);
		$this->load->view('required/footer',TRUE);
		//result [] ten, tenUrl, hinh1, noidung, gia
		//counter : int : So nguoi da truy cap
		//online : int : So nguoi dang online
		//$menu1 : string (Chỉnh sửa lại chuỗi xuất ra)
		//$menu2 : string (Chỉnh sửa lại chuỗi xuất ra)
	}
	public function loaiphong($tenLP,$sotrang=1)
	{
		$tenLP = $this->security->xss_clean($tenLP);
		$sotrang = $this->security->xss_clean($sotrang);
		if(!is_numeric($sotrang)) $sotrang = 1;
		$this->load->library('pagination');
		$this->load->model('sanpham_model');
		$data2['sanpham'] = $this->sanpham_model->getSPByTenLP($tenLP,$sotrang);
		if(count($data2['sanpham'])<=0) echo redirect(base_url());
		
		$config['base_url'] = base_url('sanpham/loaiphong');
		$config['first_link'] = '<<';
		$config['last_link'] = '>>';
		$config['anchor_class'] = 'class="pagin"'; 
		$config['total_rows'] = $this->sanpham_model->countSPByTenLP($tenLP);
		$config['per_page'] = 1;
		$config['use_page_numbers'] = TRUE;
		$this->pagination->initialize($config);
		$data2['phantrang'] = $this->pagination->create_links();
		
		$data1['thongke'] = $this->addin->thongKe();
		$data1['counter'] = $this->addin->getcounter();
		$data1['online'] = $this->addin->getonline();
		$data1['menu1'] = $this->addin->getMenuMain();
		$data1['menu2'] = $this->addin->getMenu3Cap();
		$data1['noibat'] = $this->sanpham_model->getNoiBat();
		$this->load->view('required/header-trangcon',$data1);
		$this->load->view('sanpham/loaiphong',$data2);
		$this->load->view('required/footer',TRUE);
		//result [] ten, tenUrl, hinh1, noidung, gia
		//counter : int : So nguoi da truy cap
		//online : int : So nguoi dang online
		//$menu1 : string (Chỉnh sửa lại chuỗi xuất ra)
		//$menu2 : string (Chỉnh sửa lại chuỗi xuất ra)
	}
	public function loaisanpham($tenL,$sotrang=1)
	{
		$tenL = $this->security->xss_clean($tenL);
		$sotrang = $this->security->xss_clean($sotrang);
		if(!is_numeric($sotrang)) $sotrang = 1;
		$this->load->library('pagination');
		$this->load->model('sanpham_model');
		$data2['sanpham'] = $this->sanpham_model->getSPByTenL($tenL,$sotrang);
		if(count($data2['sanpham'])<=0) echo redirect(base_url());
		
		$config['base_url'] = base_url('sanpham/loaisanpham');
		$config['first_link'] = '<<';
		$config['last_link'] = '>>';
		$config['anchor_class'] = 'class="pagin"'; 
		$config['total_rows'] = $this->sanpham_model->countSPByTenL($tenL);
		$config['per_page'] = 1;
		$config['use_page_numbers'] = TRUE;
		$this->pagination->initialize($config);
		$data2['phantrang'] = $this->pagination->create_links();
		
		$data1['thongke'] = $this->addin->thongKe();
		$data1['counter'] = $this->addin->getcounter();
		$data1['online'] = $this->addin->getonline();
		$data1['menu1'] = $this->addin->getMenuMain();
		$data1['menu2'] = $this->addin->getMenu3Cap();
		$data1['noibat'] = $this->sanpham_model->getNoiBat();
		$this->load->view('required/header-trangcon',$data1);
		$this->load->view('sanpham/loaisanpham',$data2);
		$this->load->view('required/footer',TRUE);
		//result [] ten, tenUrl, hinh1, noidung, gia
		//counter : int : So nguoi da truy cap
		//online : int : So nguoi dang online
		//$menu1 : string (Chỉnh sửa lại chuỗi xuất ra)
		//$menu2 : string (Chỉnh sửa lại chuỗi xuất ra)
	}
	public function chitietsanpham($tenSP)
	{
		$this->load->library('files');
		$tenSP = $this->security->xss_clean($tenSP);
		$this->load->model('sanpham_model');
		$data2['sanpham'] = $this->sanpham_model->getSP($tenSP);
		if(count($data2['sanpham'])<=0) echo redirect(base_url());
		
		$data1['thongke'] = $this->addin->thongKe();
		$data1['counter'] = $this->addin->getcounter();
		$data1['online'] = $this->addin->getonline();
		$data1['menu1'] = $this->addin->getMenuMain();
		$data1['menu2'] = $this->addin->getMenu3Cap();
		$data1['noibat'] = $this->sanpham_model->getNoiBat();
		$this->load->view('required/header-trangcon',$data1);
		$this->load->view('sanpham/chitietsanpham',$data2);
		$this->load->view('required/footer',TRUE);
		//result [] ten, hinh1, hinh2, hinh3, hinh4, noidung, gia
		//counter : int : So nguoi da truy cap
		//online : int : So nguoi dang online
		//$menu1 : string (Chỉnh sửa lại chuỗi xuất ra)
		//$menu2 : string (Chỉnh sửa lại chuỗi xuất ra)
	}
}